package com.slipper.bpmn.parser.support;

import com.slipper.bpmn.model.TaskNode;
import com.slipper.bpmn.parser.IParser;
import org.dom4j.Element;

public class ScriptNodeParser implements IParser<TaskNode> {
    @Override
    public TaskNode parser(Element element) {
        TaskNode taskNode = parser(new TaskNode(), element);
        taskNode.setScriptId(element.attributeValue("scriptId"));
        taskNode.setRemark(element.attributeValue("remark"));

        if (taskNode.getInLine().isEmpty()) {
            throw new RuntimeException("脚本节点[" + taskNode.getName() + "]必须至少有一条流入线！");
        }

        if (taskNode.getOutLine().isEmpty()) {
            throw new RuntimeException("脚本节点[" + taskNode.getName() + "]必须至少有一条流出线！");
        }

        return taskNode;
    }
}
